﻿@if (false) {<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.min.js" type="text/javascript" />}
@{string list = "list12", pager = "pager12", entity = "FinishedInDepository";}
<table id="@list" class="scroll" cellpadding="0" cellspacing="0">
</table>
<div id="@pager" class="scroll" style="text-align: center;">
</div>

<script type="text/javascript">
    jQuery(function () {
        $("#@list").jqGrid({
            url: "/@entity/index/",
            colNames: ["成品编号", "成品名称", "成品型号", "入库日期", "入库数量", "批次号", "存放货位", "备注"],
            colModel: [
            $.jgridx.strAuto1Col("ProductValueObject.Number", "/FinishedInDepository/get"),
            $.extend($.jgridx.strCol("ProductValueObject.Name"), { editable: false }),
            $.extend($.jgridx.strCol("ProductValueObject.Model"), { editable: false }),
            $.jgridx.dateCol("Date"),
            $.jgridx.intCol("Count"),
            $.jgridx.strAutoCol("Number", "/FinishedInDepository/GetNumber"),
            $.jgridx.strNullCol("Location"),
            //            { name: 'Supplier', index: 'Supplier', width: 80, search: false },
            //            { name: 'OrderNumber', index: 'OrderNumber', width: 80, search: false },
            {
            name: "Remark",
            index: "Remark",
            width: 280,
            editable: true,
            edittype: "textarea",
            search: false
        }
            ],
        //multiselect: false,
        pager: $('#@pager'),
        sortname: "InDepositoryId",

        footerrow: true,
        userDataOnFooter: true,

        loadComplete: function (data) {

            if (!data.success)
                $(this).jqGrid("clearGridData", true);
        }
    });
    $("#@list").jqGrid('navGrid', '#@pager',
        {
            edit: false,
            add: true,
            search: true,
            del: false,
            refresh: true
        },
        {
            url: "/@entity/edit/"
        },
        {
            url: "/@entity/add/",
            onClose: function () {
                $("#temptr").remove();
            }
        },
        {
            url: "/@entity/delete/"
        }, {}, {}).navSeparatorAdd("@pager", { sepclass: "ui-separator", sepcontent: '' })
        .jqGrid('navButtonAdd', "@pager", { caption: "",
            buttonicon: "ui-icon ui-icon-print",
            position: "last",
            title: "打印入库单",
            onClickButton: function () {
                var rowids = $("#@list").jqGrid('getGridParam', 'selarrrow');
                if (rowids.length == 0) {
                    Alert("警告", "请选择记录！");
                    return;
                }
                var title = "成品入库单"
                var p = $("#@list");
                var h = p.parent().parent().parent().find("table").eq(0).find("thead");
                var printhtml = []
                printhtml.push(h.html());
                $.each(p.find("tr"), function (index, value) {
                    if (inarray(rowids, $(this).attr("id"))) {
                        printhtml.push("<tr>" + $(this).html() + "</tr>");
                    }
                });

                var printdiv = $('<div id="printdiv"><h1>' + title + '</h1><table cellspacing="0" cellpadding="0" border="0">' + printhtml.join('') + '</table></div>');
                $.each(printdiv.find("tr"), function () {
                    $(this).children().eq(0).remove();
                });
                printdiv.find("span").remove();
                Print(printdiv);
            }
        })
        .jqGrid('navButtonAdd', "@pager", { caption: "",
            buttonicon: "ui-icon ui-icon-disk",
            position: "last",
            title: "导出",
            onClickButton: function () {
                if ($("#@(list)excel").length == 0) {
                    $(this).after('<form id="@(list)excel" method="post" action="/@entity/Report.xls"></form>');
                }
                $("#@(list)excel").submit()
                //$.ajax("/PartsInDepository/Report");
            }
        });
});
</script>